/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.awt.image.BufferedImage;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Fernando
 */
public class PredictionTm extends Graphic {
    private double[] temperature;

    public PredictionTm(double[] temperature) {
        this.temperature = temperature;
    }

    public BufferedImage Draw() {
        XYSeries series = new XYSeries("Proyeccion");
        
        PredictionControl Rg = new PredictionControl();
        double[] res = Rg.lineal(temperature);

        for (int i = 0; i < (temperature.length) + 10; i++) {
            series.add(i + 1, (res[0] * (i + 1)) + res[1]);
        }

        XYDataset juegoDatos = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart("", "Tiempo", "Temperatura", juegoDatos, PlotOrientation.VERTICAL, false, false, true);
        
        final XYPlot plot = (XYPlot) chart.getPlot();
        final NumberAxis domainAxis = (NumberAxis)plot.getDomainAxis();
        final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)plot.getRenderer();
        renderer.setSeriesShapesVisible(0, true);
        BufferedImage image = chart.createBufferedImage(500,300);   
        return image;
    }
    
}
